﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Job.Entity;
using Job.Data.Interfaces;
using Job.Logic.Common;

namespace Job.Logic.Company
{
    public class CompanyLogic
    {
        IJobCompanyInfoDao dao = DataAccess.companyInfoDao;
        public bool Insert(JobCompanyInfo company)
        {
            dao.Insert(company);
            return true;
        }

        //根据用户名，获得用户的信息
        public JobCompanyInfo GetCompanyByLogin(string loginCode)
        {
            IList<JobCompanyInfo> list = dao.FindByLoginName(loginCode);
            if (null == list || list.Count == 0) return null;
            return list[0];
        }

        //根据邮箱，获得邮箱的信息
        public IList<JobCompanyInfo> GetCompanyByEmail(string email)
        {
            IList<JobCompanyInfo> list = dao.QuickFindByContactEmail(email);
            return list;
        }

        public void UpdateBaseInfo(JobCompanyInfo company)
        {
            dao.UpdateBaseInfo(company);
        }

        public void UpdateCompanyIntro(int companyId, string intro)
        {
            JobCompanyInfo company = new JobCompanyInfo();
            company.CompanyInfoId = companyId;
            company.CompanyIntro = intro;
            dao.UpdateCompanyIntro(company);
        }

        public void UpdateProductIntro(int companyId, string intro)
        {
            JobCompanyInfo company = new JobCompanyInfo();
            company.CompanyInfoId = companyId;
            company.ProductIntro = intro;
            dao.UpdateProductIntro(company);
        }

        public JobCompanyInfo GetCompanyInfo(int id)
        {
            return dao.Find(id);
        }

        public JobCompanyInfo GetLogo(int id)
        {
            return dao.FindLogo(id);
        }

        public int UpdateLogo(JobCompanyInfo info)
        {
            return dao.UpdateLogo(info);
        }

        public void UpdatePassword(JobCompanyInfo obj)
        {
            dao.UpdatePassword(obj);
        }

        public void Delete(int id)
        {
            IJobPositionInfoDao positionDao = DataAccess.positionInfoDao;
            positionDao.DeleteByCompanyInfoId(id);

            JobCompanyInfo info = new JobCompanyInfo();
            info.CompanyInfoId = id;
            dao.Delete(info);
        }

        public void SetStatus(int id, bool status)
        {
            JobCompanyInfo info = new JobCompanyInfo();
            info.CompanyInfoId = id;
            info.AccountStatus = status;
            dao.UpdateStatus(info);
        }

    }
}
